{% extends 'base.html' %}

{% load bootstrap_pagination %}
{% load forum_tags %}

{% block main %}
    <main class="col-md-8 mb-1">
        <ul class="list-group">
            {% block post_list_head %}
                <li class="list-group-item">
                    <span class="pull-right">收藏总数 {{ favorite_list.count }}</span>
                    <nav>
                        <a href="{% url 'forum:index' %}">django forum demo</a> >
                        <a href="{{ user.get_absolute_url }}">{{ user.nickname }}</a> >
                        <a>全部收藏</a>
                    </nav>
                </li>
            {% endblock post_list_head %}

            {% for favorite in page_obj %}
                <li class="list-group-item">
                    {% block post_item %}
                        {% include 'forum/_post_item.html' with post=favorite.follow_object %}
                        <button class="btn btn-sm btn-outline-info mt-1">
                            <a class="unfavorite-btn"
                               href="{% url 'follows:unfollow_all' content_type_id=favorite.follow_object|get_ctype_pk object_id=favorite.follow_object.pk ftype='favorite' %}">
                                <i class="fa fa-times" aria-hidden="true"></i> 取消收藏
                            </a>
                        </button>
                    {% endblock post_item %}
                </li>
            {% empty %}
                <li class="list-group-item">暂无收藏</li>
            {% endfor %}
            {% if post_list and paginator.num_pages > 1 %}
                {% bootstrap_paginate page_obj size='small' range=10 show_first_last='true' %}
            {% endif %}
        </ul>
    </main>
{% endblock main %}

{% block script %}
    <script>
        $(".unfavorite-btn").click(function () {
            $.post($(this).attr("href"), {});
            $(this).parent().parent().remove();
            return false
        });
    </script>
{% endblock script %}